package org.example.countDownLatch;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class cyclicbarrierTest {
    public static void main(String[] args) {
        CyclicBarrier cb = new CyclicBarrier(8,()->{
            System.out.println("召唤神龙成功");
        });
        for (int i = 1; i <= 8; i++) {
            final int i_f = i;
            new Thread(()-> {

                System.out.println(Thread.currentThread().getName()+"收集了第"+i_f+"颗龙珠");
                try {
                    cb.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            }).start();



        }
    }
}
